<?php 
require './configs/config.php';

// 自动加载类
function mvc_autoload($classname)
{
    // echo $classname;
    if (file_exists("./models/{$classname}.class.php")) {
        require "./models/{$classname}.class.php";
    }elseif(file_exists("./controllers/{$classname}.class.php")){
        require "./controllers/{$classname}.class.php";
    }else{
        header('HTTP/1.0 404 not found');
        header('Status:404 not found');//IE兼容
        echo '<h1>404 NOT FOUND!!!</h1>';
        exit;
    }
}

require './libs/Smarty.class.php';
$smarty = new Smarty();
// var_dump($smarty);
//模版配置
$smarty->setTemplateDir('./views')
       ->setCompileDir('./runtime/views_c')
       ->setConfigDir('./configs')
       ->setCacheDir('./runtime/caches');
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
//配置缓存
$smarty->caching = false;//关闭缓存
$smarty->cache_lifetime = 10;//缓存10秒

// spl_autoload_register   SPL里的方法
spl_autoload_register('mvc_autoload');

//获取用户参数   index.php?m=控制器名&a=操作名
//index.php?m=Goods&a=add
//获取控制器名
$m = (!empty($_GET['m']))?$_GET['m']:'Index';
//获取操作名
$a = (!empty($_GET['a']))?$_GET['a']:'index';

//拼接类名
$classname = $m.'Controller';
//实例化控制器
$controller = new $classname();

// var_dump($controller);
$controller->$a();


